package chloroform.json.comp

import scaladuct.PropertyValue
import chloroform.json.{JsonBuilderFactory, CookiePropertyProcessingContext, GenericFactoryForElement}
import scaladuct.memento.MementoRecordingGateway
import argo.jdom.JsonRootNode

/**
 * User: zslajchrt
 * Date: 16.5.11
 * Time: 20:02
 */

object Mementos {
  def getConstructors =
    List(new MementoInfoForFieldHolderConstructor)
}

class MementoInfoForField extends JsonComposite {
  val isParameter = boolean()

}

class MementoInfoForFieldHolder extends JsonComposite {
  val MementoInfoForField = struct(new MementoInfoForField)
}

class MementoInfoForFieldHolderConstructor
  extends GenericFactoryForElement[PropertyValue[_], CookiePropertyProcessingContext, JsonBuilderFactory[JsonRootNode]] {

  def create(property: PropertyValue[_], ctx: CookiePropertyProcessingContext): Option[JsonBuilderFactory[JsonRootNode]] = {
    val mementoInfoHolder = new MementoInfoForFieldHolder
    mementoInfoHolder.MementoInfoForField().isParameter <=
      ctx.cookieGateway.asInstanceOf[MementoRecordingGateway[_]].isMementoParameter(property.name)
    Some(mementoInfoHolder)
  }

}
